#!/bin/bash
#########################################################################
# Author      : zkk@crscd.com.cn
# Created Time: Thu 26 Mar 2015 05:33:39 AM PDT
# File Name   : mkramdisk_p1.sh
# Description : 
#########################################################################
RDSIZE=20000
BLKSIZE=1024

ROOTFS=rootfs-basic

echo ""
echo "Script to generate initial ramdisk for embedde linux -- Part 1"
echo "Script will copy $ROOTFS and generate a ramdisk"
echo ""

# check the rootfs-basic
echo ""
echo "rootfs-basic exist. start to release it!"
echo ""
# Create an empty ramdisk image
echo "dd if=/dev/zero of=/tmp/ramdisk.img bs=$BLKSIZE count=$RDSIZE"
dd if=/dev/zero of=/tmp/ramdisk.img bs=$BLKSIZE count=$RDSIZE
echo ""
# Make it an ext2 mountable file system
echo "/sbin/mke2fs -F -m 0 -b $BLKSIZE /tmp/ramdisk.img $RDSIZE"
/sbin/mke2fs -F -m 0 -b $BLKSIZE /tmp/ramdisk.img $RDSIZE
echo ""
# Mount it so that we can populate
echo "mount /tmp/ramdisk.img ./new -t ext2 -o loop=/dev/loop1"
mount /tmp/ramdisk.img ./new -t ext2 -o loop=/dev/loop1
echo ""
# copy from old to new
echo "cp ./$ROOTFS/* ./new/ -r"
cp -a -r ./$ROOTFS/* ./new/
echo ""
echo "Finished Part 1"
echo "Now make changes as you like in ./new, then run the Part 2"
echo ""
